#include <iostream>
#include "Database.h"
#include "Login.h"
#include "lecturer.h"
#ifndef DATABASE_FILE
#define DATABASE_FILE "Database.Assn2"
using namespace std;

int main(){
/*Database *db;
db = new Database("Database.Assn2");
db->query("CREATE TABLE users (userID INTEGER PRIMARY Key, userName VARCHAR(255), password VARCHAR(255), role VARCHAR(255), accountStatus VARCHAR(255));");
db->query("INSERT INTO users (userName, password, role, accountStatus) VALUES('admin', 'admin', 'admin', 'unlocked')");
db->query("CREATE TABLE admin (userID INTEGER, userName VARCHAR(255), firstName VARCHAR(255), lastName VARCHAR(255), email VARCHAR(255));");
db->query("INSERT INTO admin VALUES ('1','admin','firstNAME','lastNAME','admin@admin.com')");
db->query("CREATE TABLE student (userID INTEGER, userName VARCHAR(255), firstName VARCHAR(255), lastName VARCHAR(255), email VARCHAR(255));");
vector<vector<string> > result = db->query("SELECT * FROM users;");
for(vector<vector<string> >::iterator it = result.begin(); it < result.end(); ++it)
{
	vector<string> row = *it;
}
db->close();*/
    Login LA;
    Lecturer L;
    
    cout << "Welcome to ------" << endl;
    cout << "Proceeding to login page." << endl;
    cout << "Failure to log in for more than three time will result in lock "
         << "of system." << endl << endl;

    int success = -1;
    do {
        success = LA.getLogin();
        //If not successful, increase loginTries
        if (success == -1) {
            LA.increaseLoginTries();
        }
        cout << "Login Tries: " << LA.getLoginTries() << endl << endl;
        if (LA.getLoginTries() > 3) {
            cout << "More than three tries have been registered." << endl;
            cout << "Proceeding to lock the register." << endl;
            cout << "LOCKED" << endl;
            return 0;
        }
    } while (success == -1);

    if(LA.getRole() == "admin"){
        while (1) {
            int choice = 0;
            cout << "ADMIN INTERFACE" << endl;
            cout << "1) Change password" << endl;
            cout << "2) Proceed to admin interface" << endl;
            cout << "Enter your choice: ";
            cin >> choice;
            cin.clear();
            cin.ignore(100, '\n');
            
            if (choice == 1) {
            LA.changePassword();           
        } else if (choice == 2) {
            LA.adminInterface();
        } else
            cout << "Incorrect Choice. Please try again." << endl << endl;
        }
    }
     if (LA.getRole() == "lecturer")  {
        while (1) {
            int choice = 0;
            cout << "LECTURER INTERFACE" << endl;
            cout << "1) Change password" << endl;
            cout << "2) Proceed to lecturer interface" << endl;
            cout << "Enter your choice: ";
            cin >> choice;
            cin.clear();
            cin.ignore(100, '\n');
            
            if (choice == 1) {
            LA.changePassword();           
        } else if (choice == 2) {
            L.lecturerInterface();
        } else
            cout << "Incorrect Choice. Please try again." << endl << endl;
        }       
    }
     if (LA.getRole() == "student")  {
        while (1) {
            int choice = 0;
            cout << "STUDENT INTERFACE" << endl;
            cout << "1) Change password" << endl;
            cout << "2) Proceed to student interface" << endl;
            cout << "Enter your choice: ";
            cin >> choice;
            cin.clear();
            cin.ignore(100, '\n');
            
            if (choice == 1) {
            LA.changePassword();           
        } else if (choice == 2) {
            LA.studentInterface();
        } else
            cout << "Incorrect Choice. Please try again." << endl << endl;
        }       
    }
}

#endif